package com.axxc.jpa.task.rabbitmsg.provider;

import java.util.Random;

import org.springframework.amqp.core.AmqpTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import com.axxc.jpa.entity.EnumUserEntity;
import com.axxc.jpa.entity.EnumUserEntity.AccountType;
/**
 * 
 * @ClassName: RabbitMqEnumEntityMsgProviderTask 
 * @Description: 测试含枚举的实体
 * @author xxc
 * @date 2018年8月10日 上午10:54:41
 */
//@Component
public class RabbitMqEnumEntityMsgProviderTask {

	private static final Random radnom = new Random();

	private static final int PROVIDER_COUNT = 100;// 每分钟随机产生条数

	@Autowired
	private AmqpTemplate rabbitTemplate;

	@Async
	@Scheduled(cron = "0 0/1 * * * *") // cron表达式 每分钟执行一次
	public void reportCurrentTime() {
		EnumUserEntity u;
		int nextInt = radnom.nextInt(PROVIDER_COUNT);
		for (int i = 0; i < nextInt; i++) {
			u = new EnumUserEntity();
			u.setName("熊骑士" + i);
			u.setAge(i);
			u.setAccountType(i % 2 == 0 ?AccountType.TEACHER:AccountType.STUDENT);
			u.setType(i % 2 == 0 ?AccountType.TEACHER:AccountType.STUDENT);
			this.rabbitTemplate.convertAndSend("enumuser", u);
		}

	}
}
